import React, { Component } from "react";
import Square from "./Square.js";
/* function calculateWinner(squares) {
  const lines = [
    [0, 1, 2],
    [3, 4, 5],
    [6, 7, 8],
    [0, 3, 6],
    [1, 4, 7],
    [2, 5, 8],
    [0, 4, 8],
    [2, 4, 6],
  ];
  for (let i = 0; i < lines.length; i++) {
    const [a, b, c] = lines[i];
    if (squares[a] && squares[a] === squares[b] && squares[a] === squares[c]) {
      return squares[a];
    }
  }
  return null;
} */
class Board extends Component {
  constructor(props) {
    super(props);
    this.state = {
      squares: [0, 1, 2, 3, 4, 5, 6, 7, 8],
    };
  }
  //   handleClick(i) {
  //     const squares = this.state.squares.slice();
  //     // 当有玩家胜出，或者已经被填充了数字
  //     if(calculateWinner(squares) || squares[i]) return;
  //     squares[i] = this.state.xIsNext ? "x" : "o";
  //     this.setState({ squares: squares, xIsNext: !this.state.xIsNext });
  //   }
  renderSquare(i) {
    return (
      <Square
        value={this.props.squares[i] ? this.props.squares[i] : i}
        selected={this.props.selected[i]}
        winner={this.props.winnerlist[i]}
        onClick={() => this.props.onClick(i)}
      />
    );
  }
  render() {
    console.log(this.props.selected, "-=-=");
    // const winner = calculateWinner(this.state.squares);
    // let status;
    // if (winner) {
    //   status = "Winner: " + winner;
    // } else {
    //   status = "Next player: " + (this.state.xIsNext ? "X" : "O");
    // }
    // const status = "Next player: " + (this.state.xIsNext ? "x" : "o");
    return (
      <div>
        {/* <div className="status">{status}</div> */}
        {this.state.squares.map((square) => {
          if (square % 3 === 0) {
            return (
              <div className="board-row" key={square}>
                {this.renderSquare(square)}
                {this.renderSquare(square + 1)}
                {this.renderSquare(square + 2)}
              </div>
            );
          } else {
            return null;
          }
        })}
        {/* <div className="board-row">

          {this.renderSquare(0)}
          {this.renderSquare(1)}
          {this.renderSquare(2)}
        </div>
        <div className="board-row">
          {this.renderSquare(3)}
          {this.renderSquare(4)}
          {this.renderSquare(5)}
        </div>
        <div className="board-row">
          {this.renderSquare(6)}
          {this.renderSquare(7)}
          {this.renderSquare(8)}
        </div> */}
      </div>
    );
  }
}
export default Board;
